/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imenu.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Yunzi
 */
@Entity
@Table(name = "imenu_tag")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ImenuTag.findAll", query = "SELECT i FROM ImenuTag i"),
    @NamedQuery(name = "ImenuTag.findById", query = "SELECT i FROM ImenuTag i WHERE i.id = :id"),
    @NamedQuery(name = "ImenuTag.findById", query = "SELECT i FROM ImenuTag i WHERE i.id = :id"),
    @NamedQuery(name = "ImenuTag.findByStoreId", query = "SELECT i FROM ImenuTag i WHERE i.storeId = :storeId"),
    @NamedQuery(name = "ImenuTag.findByUpdateTime", query = "SELECT i FROM ImenuTag i WHERE i.updateTime = :updateTime")})
public class ImenuTag implements Serializable, Comparable {

    @Basic(optional = false)
    @NotNull
    @Column(name = "update_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", insertable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "name")
    private String name;
    @Lob
    @Size(max = 65535)
    @Column(name = "description")
    private String description;
    @JoinColumn(name = "store_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private ImenuStore storeId;
        @OneToMany(mappedBy = "tag")
    private Collection<ImenuCourse> imenuCourseCollection;

    public ImenuTag() {
    }

    public ImenuTag(Integer id) {
        this.id = id;
    }

    public ImenuTag(Integer id, String name, Date updateTime) {
        this.id = id;
        this.name = name;
        this.updateTime = updateTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public ImenuStore getStoreId() {
        return storeId;
    }

    public void setStoreId(ImenuStore storeId) {
        this.storeId = storeId;
    }

    @XmlTransient
    public Collection<ImenuCourse> getImenuCourseCollection() {
        return imenuCourseCollection;
    }

    public void setImenuCourseCollection(Collection<ImenuCourse> imenuCourseCollection) {
        this.imenuCourseCollection = imenuCourseCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        System.out.println("ImenuTag.equals() 1 object = " + object);
        if (!(object instanceof ImenuTag)) {
            System.out.println("ImenuTag.equals() 2 object = " + object);
            return false;
        }
        ImenuTag other = (ImenuTag) object;
        System.out.println("ImenuTag.equals() 3 this = " + this + " other=" + other);
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            System.out.println("ImenuTag.equals() 4 this = " + this + " other=" + other);
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.imenu.entity.ImenuTag[ id=" + id + " ]";
    }

    @Override
    public int compareTo(Object o) {
        //throw new UnsupportedOperationException("Not supported yet.");
        return this.id.compareTo(((ImenuTag)o).id);
    }
}
